import { browserWindowOption, winURL } from '@/config';
const { BrowserWindow, remote, ipcMain } = require('electron')

const isDevelopment = process.env.NODE_ENV !== 'production'
export const createBrowserWindow = (
  {
    url,
    devTools = false,
    options
  }
) => {
  let childrenWindow = null
  childrenWindow = new BrowserWindow({ ...browserWindowOption(), show: true, ...options });
  if (process.env.NODE_ENV === 'development' && devTools) {
    childrenWindow.webContents.openDevTools();
  }
  childrenWindow.loadURL(`${winURL}/#${url}`);
  childrenWindow.on('closed', () => {
    childrenWindow = null;
  });
  ipcMain.on(`close${url}`, e =>
    childrenWindow.close()
  );
  //最小化当前多窗口
  ipcMain.on(`minimize${url}`, e =>
    calendarWin.minimize()
  );
  // childrenWindow.webContents.openDevTools();
  return childrenWindow;
};



export const uuid = () => {
  const S4 = () => {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  };
  return S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4();
};


export const enterMain = () => {
  window.electronAPI.setResizable(true)
  window.electronAPI.switchPage()
  window.electronAPI.setMinimumSize({ width: 1200, height: 700 })
  window.electronAPI.setWinSize({ width: 1200, height: 700, center: true })
  window.electronAPI.switchPage()
}

export const enterLogin = () => {
  window.electronAPI.switchPage()
  window.electronAPI.setResizable(true)
  window.electronAPI.setMinimumSize({ width: 380, height: 630 })
  window.electronAPI.setWinSize({ width: 380, height: 630, center: true })
  if (process.env.NODE_ENV === 'production') {
    window.electronAPI.setResizable(false)
  }
  if (process.env.VUE_APP_OPENTOOL) {
    window.electronAPI.setResizable(true)
  }
  window.electronAPI.switchPage()
}



export const groupState = {
  15: "群主解散了群聊",
  14: "你被移出群聊",
  8: "你已被群管理员设置为禁言",
  6: "全员禁言开启",
  500: "你已退出群聊"
}